# Maintainer: BlackIkeEagle <ike DOT devolder AT gmail DOT com>
# Contributor: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor: John Gerritse <john.gerritse@gmail.com>

pkgname=atop
pkgver=2.9.0
pkgrel=1
pkgdesc='A system and process level monitor'
arch=('loong64' 'x86_64')
url='https://www.atoptool.nl/'
license=('GPL')
depends=('ncurses' 'sh' 'zlib')
optdepends=(
    'python-pynvml: NVIDIA gpu reporting AUR'
)
backup=('etc/default/atop')
source=("https://www.atoptool.nl/download/atop-${pkgver/_/-}.tar.gz"
        'atop.default'
        "https://github.com/Atoptool/atop/pull/262.patch")
sha512sums=('a79eb142b16c32d43ee3220bdaf3a1b3861b713bfd86f4e7d2241cadf84f5d09a054289442e4d91499852069735b8cd16760c6fc46f65639fe429ceb68534544'
            '3583738b48d9b5ed1ada323a753cd30bfd41a118d7f96ab9f536858ac356cdd5dd2acf30de5c000745c0b817e9e0ee115731fbe9828086488c3c9df773a05d08'
            '56e92d65389b06f981da20a15302484e0de76595ee3667f980789b424921e44699b5ef4e1e23a0576110aa11e2f23ae3fda3e1eef21b884250b74dd4053eba63')

prepare() {
    cd "$pkgname-$pkgver"
    patch -p1 -i "$srcdir/262.patch"
}

build() {
    cd "$pkgname-$pkgver"
    make
}

package() {
    cd "$pkgname-$pkgver"
    ## default folder not properly created
    mkdir -p "$pkgdir/etc/default"
    make DESTDIR="$pkgdir" install \
        SBINPATH=/usr/bin \
        SYSDPATH=/usr/lib/systemd/system
    install -Dm644 "$srcdir/atop.default" "$pkgdir/etc/default/atop"
    # enable atop-rotate.timer by default
    install -dm755 "$pkgdir/usr/lib/systemd/system/timers.target.wants"
    ln -s ../atop-rotate.timer \
        "$pkgdir/usr/lib/systemd/system/timers.target.wants/atop-rotate.timer"
}
